
typedef T JsonParse<T>(dynamic data);

class ResultBean<T> {
  T? data;
  int? code;
  String? msg;

  ResultBean({this.data, this.code=-1, this.msg=''});

  @override
  String toString() {
    return 'RepResult{data: $data, status: $code, msg:$msg}';
  }

  static ResultBean<T> fromData<T>(dynamic data,JsonParse<T>? jsonParse) {
    return ResultBean<T>(
      msg: data['msg'],
      data: jsonParse?.call(data['data']),
      code: data['code'],
    );
  }

  static ResultBean<T> error<T>(dynamic err) {
    return ResultBean(
      msg: err['msg'],
      data: null,
      code:err['code'],
    );
  }
}
